package com.lwj.controller;

import com.lwj.constant.ConstantDefinition;
import com.lwj.entity.RestEntity;
import com.lwj.entity.User;
import com.lwj.mapper.UserDAO;
import com.lwj.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
/**
 * @Author lwj
 */
@Api(tags = "用户接口")
@Controller
public class UserController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;
    @Autowired
    private UserDAO userDAO;

    @ApiOperation(value = "登录")
    @GetMapping("/login")
    public String login(@RequestParam(value = "username", required = false) String username,  @RequestParam(value = "password", required = false) String password,HttpServletRequest request){
        return userService.login(username,password,request);
    }

    @ApiOperation(value = "测试json返回")
    @GetMapping(value = "/json", produces = "application/json; charset=utf-8")
    @ResponseBody
    public RestEntity<User> testJson(HttpServletRequest request){
        User user = userDAO.selectByPrimaryKey(2);
        return RestEntity.success(user);
    }
}
